package com.junit;

import com.dao.impl.BaseDao;
import com.dao.impl.BookDaoImp;
import com.pojo.Book;
import com.pojo.Page;
import com.utils.jdbcUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ScalarHandler;
import org.junit.Test;

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.SQLException;
import java.time.DayOfWeek;
import java.util.List;

public class BooksUtils {
    BookDaoImp b = new BookDaoImp();


    public static void main(String[] args) {
        QueryRunner query = new QueryRunner();
            Connection conn = jdbcUtils.getConnection();
            try {
                System.out.println(query.query(conn,"SELECT COUNT(*) FROM t_book WHERE price BETWEEN 1 AND 10000",new ScalarHandler()));
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }finally {
                try {
                    conn.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }

    }
    @Test
    public void w(){
        Page<Book> p = new Page<Book>();
        p.setPageNo(100);
        System.out.println(p.getPageNo());
    }
    @Test
    public void te(){
        BaseDao b = new BaseDao();
        Object obj= b.queryForSingleValue("select count(*) from t_book");
        Object obje = 20;
        String str = String.valueOf(obj);
       int ii= Integer.parseInt(str);

        System.out.println(ii);
        System.out.println((Integer) obje);

    }
    //添加
    @Test
    public void test1(){
       b.addBook(new Book(21 , "人月神话" , "刚哥" , new BigDecimal(88.15) , 20 , 80 , "项目/static/img/default.jpg"));
    }
    //修改
    @Test
    public void test2(){
        b.updateBook(new Book(21 , "我是修改后的数据" , "刚哥" , new BigDecimal(88.15) , 20 , 80 , "项目/static/img/default.jpg"));
    }
    //删除
    @Test
    public void test3(){
        b.delBookById(21);
    }
    //查询一个
    @Test
    public void test4(){
       Book bb =  b.queryBookById(2);
        System.out.println(bb);
    }
    //查询所有
    @Test
    public void test5(){
        List<Book> bb =  b.queryBooks();
        for(Book bbbb:bb){
            System.out.println(bbbb);
        }
    }
}
